package com.bawei.week3.fragment;


import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.bawei.week3.R;
import com.bawei.week3.adapter.ContactADapter;
import com.bawei.week3.adapter.MusicAdapter;
import com.bawei.week3.entity.ContactsEntity;
import com.bawei.week3.entity.MusicEntity;
import com.bawei.week3.utils.ContentUtils;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MusicFragment extends Fragment {

    private List<MusicEntity> list;
    private ListView listView;
    private MusicAdapter musicAdapter;

    public MusicFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_music, container, false);
        listView = view.findViewById(R.id.lv);
        list = ContentUtils.getSongs(getContext());
        musicAdapter  = new MusicAdapter(list,getContext());
        listView.setAdapter(musicAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //发送广播
                Intent intent = new Intent();
                intent.setAction("com.bawei.music");
                Bundle bundle = new Bundle();
                bundle.putString("name",list.get(position).getName());
                intent.putExtras(bundle);
                getActivity().sendBroadcast(intent);//普通广播
               // getActivity().sendStickyBroadcast(intent);//粘性广播
               // getActivity().sendOrderedBroadcast(intent,null);//有序广播
            }
        });
        return view;
    }






}
